package com.cws4cloud.cws.sdAdmin.biz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cws4cloud.cws.common.core.util.TreeUtil;
import com.cws4cloud.cws.sdAdmin.biz.mapper.SysWebsiteMapper;
import com.cws4cloud.cws.sdAdmin.api.dto.WebsiteTree;
import com.cws4cloud.cws.sdAdmin.api.entity.SysWebsite;
import com.cws4cloud.cws.sdAdmin.api.service.SysWebsiteService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author zhulj
 * @date 2021-03-05 15:07:23
 */
@Service
@RequiredArgsConstructor
public class SysWebsiteServiceImpl extends ServiceImpl<SysWebsiteMapper, SysWebsite> implements SysWebsiteService {

	private final SysWebsiteMapper websiteMapper;

	@Override
	public List<WebsiteTree> listWebsiteTrees(boolean lazy, Integer parentId, String name) {
		if (lazy){
			return getWebsiteTree(websiteMapper.listWebsiteTree(parentId,name),parentId);
		} else {
			return getWebsiteTree(websiteMapper.listWebsiteTree(null,name),-1);
		}

	}

	private List<WebsiteTree> getWebsiteTree(List<WebsiteTree> websites,Integer parentId) {
		return TreeUtil.build(websites, parentId);
	}
}
